<template>
   
  <div class="app-container">
    <!-- 素材审核 -->
    <el-card class="filter-container" shadow="never">
      <div>
        <i class="el-icon-search"></i>
        <span>筛选搜索</span>
        <el-button
          style="float: right"
          type="primary"
          @click="handleSearchList()"
          size="small"
        >
          查询搜索
        </el-button>
        <el-button
          style="float: right; margin-right: 15px"
          @click="handleResetSearch()"
          size="small"
        >
          重置
        </el-button>
      </div>
      <div style="margin-top: 15px">
        <el-form
          :inline="true"
          :model="listQuery"
          size="small"
          label-width="140px"
        >
          <el-form-item label="楼盘名称：">
            <el-input
              v-model="listQuery.loupanName"
              class="input-width"
              placeholder="楼盘名称"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item label="订单编号：">
            <el-input
              v-model="listQuery.orderNumber"
              class="input-width"
              placeholder="订单编号"
              clearable
            ></el-input>
          </el-form-item>
        
        </el-form>
      </div>
    </el-card>
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>数据列表</span>
      <!-- <el-button
        size="mini"
        class="btn-add"
        @click="handleAdd()"
        style="margin-left: 20px"
        >添加活动</el-button
      >
      <el-button size="mini" class="btn-add" @click="handleShowSessionList()"
        >秒杀时间段列表</el-button
      > -->
    </el-card>
    <div class="table-container">
      <el-table
        ref="flashTable"
        :data="list"
        style="width: 100%"
        v-loading="listLoading"
        border
      >
      <!-- 多选复选框 -->
        <!-- <el-table-column
          type="selection"
          width="60"
          align="center"
        ></el-table-column> -->
        <el-table-column label="订单编号" width="200" align="center">
          <template slot-scope="scope">{{ scope.row.orderNumber }}</template>
        </el-table-column>
        <el-table-column label="素材" align="center">
          <!-- 满足图片或vedio -->
          <template slot-scope="scope">
            <!-- <img
              :src="'http://'+scope.row.sourceurl"
              alt=""
              v-if="scope.row.sucaiType === '图片'"
            />
            <video :src="'http://'+scope.row.sourceurl" v-else></video> -->
            <el-button  
            size="mini"
            type="success"
            @click="showSucai(scope.$index,scope.row.sourceurl,scope.row.sucaiType)">
              查看素材
            </el-button>
            
          </template>
        </el-table-column>
        <el-table-column label="素材类型" width="100" align="center">
          <template slot-scope="scope">{{ scope.row.sucaiType }}</template>
        </el-table-column>
        <el-table-column label="电梯号" width="140" align="center">
          <template slot-scope="scope">{{ scope.row.liftNumber }}</template>
        </el-table-column>
        <el-table-column label="楼盘名称" width="140" align="center">
          <template slot-scope="scope">{{ scope.row.name }}</template>
        </el-table-column>
        <el-table-column label="审核状态" width="200" align="center">
          <template slot-scope="scope">{{
            scope.row.reviewstatus | showStatus
          }}</template>
        </el-table-column>
        <el-table-column label="审核意见" width="140" align="center">
          <template slot-scope="scope">{{ scope.row.idea }}</template>
        </el-table-column>
        <!-- <el-table-column label="审核意见" width="140" align="center">
          <template slot-scope="scope">{{scope.row.endDate | formatDate}}</template>
        </el-table-column> -->
        <el-table-column label="操作" width="100" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="success"
              @click="handleStatusChange(scope.$index, scope.row, 1)"
              >审核
            </el-button>
            <!-- <el-button
              size="mini"
              type="danger"
              @click="handleStatusChange(scope.$index, scope.row, 2)"
              >审核拒绝
            </el-button> -->
          </template>
          
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="listQuery.pageNum"
        :page-size="listQuery.pageSize"
        :page-sizes="[5, 10, 15]"
        :total="total"
      >
      </el-pagination>
    </div>
    <!-- 展示素材内容弹窗 -->
    <el-dialog
  title="素材内容"
  :visible.sync="show"
  width="60%"
  :before-close="handleClose">
  <div class="sucai">
    <p>素材类型：{{sucaiType}}</p>
    <img :src="'http://'+showSucaiUrl" alt="素材图片" v-if="sucaiType==='图片'"/>
    <video ref="sucaiVideo" v-else controls>

      <source :src="'http://'+showSucaiUrl" type="video/mp4">
      您的浏览器不支持video标签
    </source>
    </video>

  </div>
 
</el-dialog>
    <!-- 审核弹窗 -->
    <el-dialog title="素材审核" :visible.sync="dialogVisible" width="40%">
      <el-form
        :model="flashPromotion"
        ref="flashPromotionForm"
        label-width="150px"
        size="small"
      >
        <el-form-item label="审核意见：">
          <el-input
            v-model="idea"
            style="width: 250px"
          ></el-input>
        </el-form-item>
        <el-form-item label="审核结果">
          <el-radio-group v-model="reviewstatus">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="2">拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" size="small">取 消</el-button>
        <el-button type="primary" @click="handleDialogConfirm()" size="small"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  fetchList,
  deleteFlash,
  createFlash,
  updateFlash,
} from "@/api/flash";
import { formatDate } from "@/utils/date";
import { getSourcNo,updateStatus } from "@/api/asource";
// updateStatus
const defaultListQuery = {
  pageNum: 1,
  pageSize: 5,
  keyword: null,
  loupanName:'',
  orderNumber:''
};
const defaultFlashPromotion = {
  id: null,
  title: null,
  startDate: null,
  endDate: null,
  status: 0,
};
export default {
  name: "flashPromotionList",
  data() {
    return {
      status: [0, 1],
      changeStatusId:'',//素材id
      idea:'',//审核意见
      reviewstatus:'',//素材审核类型
      show:false,//展示素材弹窗
      showSucaiUrl:'',
      sucaiType:'',
      listQuery: Object.assign({}, defaultListQuery),
      list: null,
      total: null,
      listLoading: false,
      dialogVisible: false,
      flashPromotion: Object.assign({}, defaultFlashPromotion),
      isEdit: false,
    };
  },
  created() {
    this.getList();
  },
  filters: {
    showStatus(status) {
      // console.log(status);
      if (status == 0) {
        return "未审核";
      } else if (status == 2) {
        return "审核未通过";
      }
    },
    formatActiveStatus(row) {
      let nowTime = new Date().getTime();
      if (nowTime >= row.startDate && nowTime <= row.endDate) {
        return "活动进行中";
      } else if (nowTime > row.endDate) {
        return "活动已结束";
      } else {
        return "活动未开始";
      }
    },
    formatDate(time) {
      if (time == null || time === "") {
        return "N/A";
      }
      let date = new Date(time);
      return formatDate(date, "yyyy-MM-dd");
    },
  },
  methods: {
    //关闭展示素材内容弹窗
    handleClose(done) {
      this.showSucaiUrl=''
       const video=this.$refs.sucaiVideo
      if(video&&!video.paused){
        video.pause()
      }
      done();
      },
      //开启
      showSucai(index,url,type){
        // console.log(index,url);
this.show=true
this.showSucaiUrl=url
this.sucaiType=type
      },
    handleResetSearch() {
      this.listQuery = Object.assign({}, defaultListQuery);
    },
    handleSearchList() {
      this.listQuery.pageNum = 1;
      // console.log(this.listQuery);
      this.getList();
    },
    handleSizeChange(val) {
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.pageNum = val;
      this.getList();
    },
    handleAdd() {
      this.dialogVisible = true;
      this.isEdit = false;
      this.flashPromotion = Object.assign({}, defaultFlashPromotion);
    },
    handleShowSessionList() {
      this.$router.push({ path: "/sms/flashSession" });
    },
    handleStatusChange(index, row, tipindex) {
      this.dialogVisible=true
      this.changeStatusId=row.id//素材id
      this.idea=''
      // let tip = {
      //   1: { msg: "确定该订单素材审核通过吗？", type: "success" },
      //   2: { msg: "确定该订单素材审核拒绝吗？", type: "success" },
      // };
      // console.log(index, row, tipindex);
      // this.$confirm(tip[tipindex].msg, "提示", {
      //   confirmButtonText: "确定",
      //   cancelButtonText: "取消",
      //   type: "warning",
      // })
      //   .then(() => {
      //     // console.log(tipindex,'审核');
      //     const data = { id: row.id, status: tipindex };
      //     console.log(data);
      //     updateStatus(data).then(response => {
      //       this.$message({
      //         type: 'success',
      //         message: '修改成功!'
      //       });
      //     });
      //   })
      //   .catch(() => {
      //     this.$message({
      //       type: "info",
      //       message: "取消修改",
      //     });
      //     this.getList();
      //   });
    },
    handleDelete(index, row) {
      this.$confirm("是否要删除该活动?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        deleteFlash(row.id).then((response) => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.getList();
        });
      });
    },
    handleUpdate(index, row) {
      this.dialogVisible = true;
      this.isEdit = true;
      this.flashPromotion = Object.assign({}, row);
    },
    handleDialogConfirm() {
if(this.reviewstatus===''){
  this.$message({
    type:"warning",
    message:"请选择审核类型！"
  })
}else if(this.reviewstatus===2&&this.idea===''){
  this.$message({
    type:"warning",
    message:"请输入拒绝原因！"
  })
}else{
  // console.log('id',this.changeStatusId, '评语',this.idea,'选择审核结果',this.reviewstatus);

  this.$confirm("是否要确认?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        // console.log('id',this.changeStatusId, '评语',this.idea,'选择审核结果',this.reviewstatus);
             const data={id:this.changeStatusId,idea:this.idea,reviewstatus:this.reviewstatus}

              updateStatus(data).then(response => { 
                this.dialogVisible = false;
            this.$message({
              type: 'success',
              message: '审核成功!'
            });
            this.getList()
          });
      });
}
  
    },
    handleSelectSession(index, row) {
      // console.log("审核信息：", index, row);
      // this.$router.push({path:'/sms/selectSession',query:{flashPromotionId:row.id}})
    },
    getList() {
      this.listLoading = true;
      // const data={pageNum:this.pageNum,pageSize:this.pageSize}
      getSourcNo(this.listQuery).then((response) => {
        // console.log(response);
        this.listLoading = false;
        this.list = response.data.list;
        this.total = response.data.total;
      });
    },
  },
};
</script>
<style scoped>

.sucai{
  
 
}
.sucai img,.sucai video{
width: 100%;
height: 100%;
}
</style>>

